#include<bits/stdc++.h>
using namespace std;
int n,m;
char grid[1006][1006];
void dfs(int x,int y) {
  if(grid[x][y]=='#')return;
  grid[x][y]='#';
  if(x-1>=0)dfs(x-1,y);
  if(y-1>=0)dfs(x,y-1);
  if(x+1<n)dfs(x+1,y);
  if(y+1<m)dfs(x,y+1);
  return;
}
int solve() {
  cin>>n>>m;
  for(int i=0;i<n;++i)
    for(int j=0;j<m;++j)
      cin>>grid[i][j];
  int ans=0;
  for(int i=0;i<n;++i)
    for(int j=0;j<m;++j) {
      if(grid[i][j]=='.') {
        dfs(i,j);
        ans++;
      }
    }
  cout<<ans<<"\n";
  return 0;
}
int main() {
  solve();
  return 0;
}
